// components/common/indexContent/indexContent.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    articlesList:[]
  },

  lifetimes: {
    attached: function(){
      this.getArticles(0)
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {

    clickImg(e){
      // console.log(e.currentTarget.dataset.picArr)
      var picarr = e.currentTarget.dataset.picArr
      wx.previewImage({
        urls:picarr
      })
    },

    getArticles(page){
      if(!page) {
        page = this.data.articlesList.length
      }
      // else{
      //   this.setData({
      //     articlesList:[]
      //   })
      // }
      wx.cloud.callFunction({
        name:"articleGetAll",
        data:{
          page:page
        }
      }).then(
        res=>{
          console.log(res);
          // console.log(this.data.articlesList.length)
          var oldList = this.data.articlesList;
          var newList = oldList.concat(res.result.data)
          this.setData({
            articlesList:newList
          })
          wx.stopPullDownRefresh()
        }
      )
    }
  }
})
